function Food(ele) {
    this.ele = ele
    this.width = 20
    this.height = 20
    this.color = 'pink'
    this.foodx = 0
    this.foody = 0
    // this.snake = new Snake(this.ele)
    this.creat()

}

Food.prototype.creat = function () {
    let food = this.ele.querySelector('.food')
    if(food)return

    let foodobj = document.createElement('div')
    // this.ele.foodobj.style.width=this.width+'px'
    // 不能加this.ele 
    foodobj.style.width = this.width + 'px'
    foodobj.style.height = this.height + 'px'
    foodobj.style.background = this.color
    foodobj.style.position = 'absolute'
    foodobj.className = 'food'
    let x = Math.floor(Math.random() * (39 - 0 + 1) + 0)
    let y = Math.floor(Math.random() * (19 - 0 + 1) + 0)
    foodobj.style.left = x * 20 + 'px'
    foodobj.style.top = y * 20 + 'px'
    this.ele.appendChild(foodobj)
    // 需要重新定义一下
    // this.move()
}

// Food.prototype.move = function () {
//     // 随机公式： Math.floor(随机数 * (最大-最小+1)+min)
//     // 要乘以宽度高度

// }
// Food.prototype.eat = function () {
//     console.log(document.querySelectorAll('div'));
//     // let food = this.ele.querySelector('.food')
//     let shex = this.snake.snakeObj[0].x
//     let shey = this.snake.snakeObj[0].y

//     // // if ((shex * 20 == this.food.offsetLeft) && (shey * 20 == this.food.offsetTop)) {
//     // //     this.snakeObj.push({
//     // //         x: this.snakeObj[this.snakeObj.length - 1].x - 1,
//     // //         y: this.snakeObj[this.snakeObj.length - 1].y,
//     // //         color: 'blue',
//     // //     })
//     // //     this.move()
//     // }
// }